//
//  XYJLanguageToViewController.m
//  徙游记-01
//
//  Created by hcios on 2017/7/19.
//  Copyright © 2017年 鹿林. All rights reserved.
//

#import "XYJLanguageToViewController.h"
#import "XYJLanguageChangeTableViewCell.h"

@interface XYJLanguageToViewController ()<UITableViewDelegate,UITableViewDataSource>{
    
    NSMutableArray *_dataArr;
    UITableView *_tableView;
}

@end

@implementation XYJLanguageToViewController

-(instancetype)init{
    if (self = [super init]) {
        _dataArr = [[NSMutableArray alloc] init];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"语言选择";
    NSArray *languageArr = @[@"中文",
                             @"粤语",
                             @"英语",
                             @"日语",
                             @"韩语",
                             @"西班牙语",
                             @"法语",
                             @"泰语",
                             @"阿拉伯语",
                             @"俄语",
                             @"葡萄牙语",
                             @"德语",
                             @"意大利语"];
    _dataArr = [[NSMutableArray alloc] initWithArray:languageArr];
    
    [self initTable];
}


-(void)initTable{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArr.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *cellID = [NSString stringWithFormat:@"cellID%ld%ld",(long)[indexPath section],(long)[indexPath row]];
    XYJLanguageChangeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[XYJLanguageChangeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    if ([_languageCategory isEqualToString:_dataArr[indexPath.row]]) {
        [cell layoutWithLanguageLabelText:_dataArr[indexPath.row] isImage:YES];
    }else{
        [cell layoutWithLanguageLabelText:_dataArr[indexPath.row] isImage:NO];
    }
    return cell;
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *language = _dataArr[indexPath.row];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"changeLanguage" object:language];
    [self.navigationController popViewControllerAnimated:YES];
} 



@end
